const textEl = document.getElementById('text')
const speedEl = document.getElementById('speed')

const text = "打印一句很长很长很长的话"

let idx = 1
let speed = 300 / speedEl.value


writerText()

function writerText() {
    textEl.innerText = text.slice(0, idx)

    idx++

    if (idx > text.length) {
        idx = 1
    }

    setTimeout(writerText,speed)
}

speedEl.addEventListener('input',(e)=>{
    speed = 300 / e.target.value
    
})